﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.Model.View;
using System.Data;

namespace HZ.Supervise.Web.Secondphase.Statistics
{
    public partial class CompanyResponse12HourByProcatalog : BasePage
    {

        IExecuteContext iec = HZ.Supervise.BLLFactory.ExecuteContext();
        IBLL_Sort isort = HZ.Supervise.BLLFactory.IBLL_Sort();
        public CompanyResponse12HourByProcatalog()
        {

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.AreaControl1.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;

                BindData();
                rblSortBind();
            }
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager_CompanyPS_PageChanged(object sender, EventArgs e)
        {
            //AspNetPager_CompanyPS.CurrentPageIndex = 1; 
            BindData();

        }
        /// <summary>
        /// 绑定药品类别
        /// </summary>
        private void rblSortBind()
        {
            //绑定中标目录类型
            DataTable dt = isort.GetSort();
            dlpsort.DataSource = dt;
            dlpsort.DataValueField = "SortID";
            dlpsort.DataTextField = "SortName";
            dlpsort.DataBind();

            this.dlpsort.Items.Insert(0, new ListItem("全部", ""));
        }
        /// <summary>
        /// 绑定数据
        /// modify  by张雄  2011.5.4
        /// </summary>
        public void BindData()
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            int t = 0;
            System.Data.DataTable dt = iec.Get12HourByProcureCatalog(vs, this.AspNetPager_CompanyPS.CurrentPageIndex, AspNetPager_CompanyPS.PageSize, out t);
            AspNetPager_CompanyPS.RecordCount = t;

            this.gvwPSLInfo.PageSize = AspNetPager_CompanyPS.PageSize;
            this.gvwPSLInfo.DataSource = dt;
            this.gvwPSLInfo.DataBind();



        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager_CompanyPS.CurrentPageIndex = 1;
        }
        /// <summary>
        /// 分页    县区
        /// by张雄
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void CompanyPSL_PS_PageChanged(object sender, EventArgs e)
        {
            BindData();

        }



        /// <summary>
        /// 导出
        /// modify  by  张雄    2011.5.5
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            int t = 0;
            System.Data.DataTable dt = iec.Get12HourByProcureCatalog(vs, 1, 0, out t);
            ExportFile.Instance.ExportData(dt, gvwPSLInfo, this.Page);
        }



        /// <summary>
        /// 查询条件
        /// </summary>
        /// <returns></returns>
        private SuperviseQuery Queryby()
        {
            SuperviseQuery vs = new SuperviseQuery();
            if (!string.IsNullOrEmpty(txtStratTime.Text.Trim()))
            {
                vs.CenSubmiitTimeFrom = Convert.ToDateTime(txtStratTime.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtEndTime.Text.Trim()))
            {
                vs.CenSubmiitTimeTo = Convert.ToDateTime(txtEndTime.Text.Trim());
            }
            vs.AreaID = HZ.Supervise.Web.Function.GetAreaIDBySQL(AreaControl1.SelectedAreaID);
            vs.ProcureCatalogID = txtProcureCatalogID.Text.Trim();
            vs.SortID = dlpsort.SelectedValue;
            if (HZ.Common.zhHansUtil.HaveChineseCode(txtProductName.Text.Trim()))
            {
                vs.ProductName = txtProductName.Text.Trim();
            }
            else
            {
                vs.PinyinCode = txtProductName.Text.Trim();
            }
            vs.MedicineModelName = txtMedicineModel.Text.Trim();
            vs.Pack = txtPack.Text.Trim();
            switch (ddlHosType.SelectedValue)
            {
                case "0":
                    break;
                case "1":
                    vs.Levels = "'3','4','5','6'";
                    break;
                case "2":
                    vs.IsCountry = "'1','2','3','4'";
                    break;
                case "3":
                    vs.IsCountry = "'2'";
                    break;
                case "4":
                    vs.IsCountry = "'1'";
                    break;
                default:
                    break;
            }

            vs.IsGovernment = ddlIsGov.SelectedValue; 
            vs.SortFields = ddlSortFields.SelectedValue  +" "+ddlSort.SelectedValue;
            return vs;
        }



        protected void gvwInfo_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            string sessionId = Guid.NewGuid().ToString();
            Control cmdControl = e.CommandSource as Control;
            GridViewRow row = cmdControl.NamingContainer as GridViewRow;
            Session[sessionId] = vs;

            if (e.CommandName == "lbnPro")
            {
                LinkButton lbnR = (LinkButton)row.FindControl("lbnPro");
                vs.ProcureCatalogID = lbnR.CommandArgument;
                Response.Redirect("CompanyResponse12HourByCompany.aspx?sesid=" + sessionId);

            }
        }
    }

}

